# coding=utf-8

import sys
import os
import subprocess
import datetime

# 获得当前时间
def getNowTime():
    now = datetime.datetime.now()
    # 转换为指定的格式:
    nowTime = now.strftime("%Y-%m-%d %H:%M:%S")
    return nowTime

def printNow(str):
    print(getNowTime() + " " + str)
    # sys.stdout.flush()

printNow(f"{sys.argv}")

exePath = sys.argv[0]
(curPath, fileName) = os.path.split(exePath)
fromPath = sys.argv[2]
targetPath = sys.argv[4]
fromPath = fromPath.replace("/", "\\")
targetPath = targetPath.replace("/", "\\")

pvrType = sys.argv[12]
printNow(f'quality1: {pvrType}')
astcType = '8x8' if pvrType == 'PVRTC1_2,UBN,lRGB' else '4x4'
printNow(f'astcType1: {astcType}')

targetFileDir, targetFileName = os.path.split(targetPath)
splitName = targetFileName.split(".")[0]
newPath = targetFileDir + "\\" + splitName + ".astc"

status = subprocess.call(f'{curPath}\\astcenc-sse2 -cl {fromPath} {newPath} {astcType} -medium', shell=True)
if status != 0:
    if status < 0:
        printNow(f"Killed by signal, {status}")
    else:
        printNow(f"Command failed with return code - , {status}")